set(DOC_INSTALL_PATH "doc")
if(UNIX)
	set(DOC_INSTALL_PATH "share/doc/${PROJECT_NAME}-${PROJECT_VERSION}")
endif(UNIX)

install(FILES LICENSE.txt DESTINATION ${DOC_INSTALL_PATH})

find_package(Doxygen)
set(WM_DOXYGEN_DOT_FOUND YES)
if(NOT DOXYGEN_DOT_EXECUTABLE)
	set(WM_DOXYGEN_DOT_FOUND NO)
endif(NOT DOXYGEN_DOT_EXECUTABLE)
mark_as_advanced(WM_DOXYGEN_DOT_FOUND)

find_package(LATEX)

set(WM_LATEX_FOUND NO)
if(LATEX_COMPILER AND MAKEINDEX_COMPILER AND PDFLATEX_COMPILER)
	set(WM_LATEX_FOUND YES)
endif(LATEX_COMPILER AND MAKEINDEX_COMPILER AND PDFLATEX_COMPILER)
mark_as_advanced(WM_LATEX_FOUND)

if(DOXYGEN_FOUND)
	set(WM_DOC_SOURCE_DIR ${CMAKE_SOURCE_DIR}/include)
	set(WM_DOC_SOURCE_PATTERNS "*.hpp")
	
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
	add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
	install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${DOC_INSTALL_PATH} COMPONENT doc)
	
	if(WM_LATEX_FOUND)
		add_custom_target(pdf
			COMMAND ${PDFLATEX_COMPILER} refman.tex
			COMMAND ${MAKEINDEX_COMPILER} refman.idx
			COMMAND ${PDFLATEX_COMPILER} refman.tex
			DEPENDS doc
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/latex)
	endif(WM_LATEX_FOUND)
endif(DOXYGEN_FOUND)

